<?php 
/***
	Jcache.1.0.php
	name:xiaojia
	email:iatt@qq.com
	qq:273142650
	time:2011.12.20 22:44
***/
	class Jcache
	{
		var $timeout;
		var $root;
		
		function init ($array) 
		{
			
			$this -> timeout = $array['timeout'];
			$this -> root = $array['root'];
			
		}
		
		function page ()
		{
			ob_end_clean();
			ob_start();
			
			$cachename = $this -> file_name();
			
			$this -> loadfile($cachename);
			
		}
		
		function file_name ()
		{
			
			$request_uri = $_SERVER['REQUEST_URI'];
			
			$cachename = md5($request_uri);
			
			return $cachename;
			
		}
		
		function loadfile ($name)
		{
			$path = $this -> root . $name;
			
			if (file_exists($path)) {
				
				clearstatcache();
				
				$hourdiff = bcdiv(time() - filemtime($path), 60 * 60);
				
				if ($hourdiff < $this -> timeout) {
					@include($path);
					exit();
				}
				
			}
			
		}
		
		function end ()
		{

			$this -> save_file($this -> file_name());
			
		}
		
		function save_file ($path) 
		{
			
			$data = ob_get_contents();
			
			$file = fopen($this -> root . $path, "wb");
			fwrite($file, $data); 
			fclose($file);
			
		}
		
		function paragraph ()
		{
		}
		
	}
?>